package com.example.administrator.myproject.user

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.widget.Toast



import cn.bmob.v3.BmobQuery
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
import com.example.administrator.myproject.R
import com.example.administrator.myproject.bean.Collect

/**
 * 接单
 */
class OrderTaking : AppCompatActivity() {
    private val TAG = "OrderTaking"
    private var recyclerView: RecyclerView? = null
    private var adapter: OrderTakingAdapter? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.order_taking)
        recyclerView = findViewById(R.id.order_taking_rv)
        recyclerView!!.layoutManager = LinearLayoutManager(this)

        adapter = OrderTakingAdapter(this)
        recyclerView!!.adapter = adapter
        val query = BmobQuery<Collect>()
        query.order("-createdAt")
        println(1111)
        query.addWhereEqualTo("state", "3")
        query.findObjects(object : FindListener<Collect>() {
            override fun done(list: List<Collect>, e: BmobException?) {
                Log.i(OrderTaking.TAG, "done: "+list.toString())
                if (e == null) {
                    adapter!!.setData(list)
                } else {
                    Toast.makeText(this@OrderTaking, "查询失败", Toast.LENGTH_SHORT).show()
                }
            }
        })
    }

    companion object {
        private const val TAG = "OrderTaking"
    }
}
